﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Net.Chirash.Twitter.TwitterClient;
using Net.Chirash.Twitter.TwitterDatabase;

namespace Net.Chirash.Twitter.TweetZone.WindowComponents.ViewModels
{
    public class DirectMessageViewModel : Net.Chirash.Twitter.TweetZone.WindowComponents.ViewModels.PagableContainerViewModel<DirectMessage>
    {
        #region Constructors

        public DirectMessageViewModel()
            : base()
        {
            this.TwitterCommand = TwitterCommandFactory.CreateLocalTwitterCommand();
        }

        #endregion

        #region Public Members

        public override string ContainerTitle
        {
            get
            {
                var ret = "DirectMessage";
                return ret;
            }
        }

        #endregion

        #region Protected Members

        //protected class DirectMessageRefreshArgs
        // : PagingEventArgs<DirectMessage>
        //{
        //    public User user;
        //}

        //protected override RefreshArgs<DirectMessage> CreateRefreshArgs(RefreshArgs<DirectMessage> args)
        //{
        //    DirectMessageRefreshArgs result = args as DirectMessageRefreshArgs;
        //    if (args == null)
        //        result = new DirectMessageRefreshArgs();

        //    base.CreateRefreshArgs(result);

        //    result.user = this.CurrentUser;

        //    return result;
        //}

        protected override void UpdateDatabase(TwitterCaching caching, IEnumerable<DirectMessage> updatelist)
        {
            caching.UpdateDirectMessages(updatelist);
        }

        protected override void RefreshDataProviding(RefreshArgs<DirectMessage> e)
        {
            var cmd = e.TwitterCommand as TwitterLocalCommand;
            if (cmd == null)
                cmd = TwitterCommandFactory.CreateLocalTwitterCommand();

            var option = new DirectMessageOption()
            {
                Count = e.RequiredCount,
                Page = 0,
                SinceID = 0
            };
            var list = cmd.GetDirectMessages(option);
            e.ResultEnumerable = list;
        }

        protected override void PagingDataProviding(PagingEventArgs<DirectMessage> e)
        {
            var caching = e.TwitterCommand as TwitterLocalCommand;
            var option = new DirectMessageOption()
            {
                Count = e.RequiredCount,
                MaxID = (e.LastData as DirectMessage).DirectMessageID - 1,
            };
            var list = caching.GetDirectMessages(option);
            e.ResultEnumerable = list;
        }

        #endregion
    }
}
